package com.study.a08Test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {

        ServerSocket ss=new ServerSocket(9000);


        //监听客户端连接
        Socket socket=ss.accept();

        //读取数据并保存在本地
        BufferedInputStream bis=new BufferedInputStream(socket.getInputStream());
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("E:\\java-code\\idea-code-study\\mysocketnet\\serverdir\\磁石骰2.png"));
        byte[] bytes=new byte[1024*1024*5];
        int len;
        while((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }


        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("文件上传成功");
        bw.newLine();
        bw.flush();
        //关闭资源

        socket.close();
        ss.close();
    }
}
